package business.application.test_bed;

import org.kth.dks.JDHT;  
import java.io.*;
import java.util.ArrayList;

public class Server {
	
	public static int numOfNodes = 15;
	
	public static void main(String[] arg) {
		try {
			
			if (arg.length>=1) 
				numOfNodes = Integer.parseInt(arg[0]);
			
			// Could declare myDHT as a java.util.Map
			// default port 4440 
			
			int port = 44000;
			
			JDHT DHTNode = new JDHT(port);
			DHTNode.put("myKey0", "myContent0");
			int i;
			for(i= 1; i< numOfNodes; i++) {
				DHTNode = new JDHT(port+i, ((JDHT)DHTNode).getReference());
				DHTNode.put("myKey"+i, "myContent"+i);
			}

			// Insert data into the DHT
			DHTNode.put("myKey"+i, "myContent"+i);
			
			// Print a reference to this node
			System.out.println( ((JDHT)DHTNode).getReference() );
			
			// Wait for input before exiting
			BufferedReader cin = new BufferedReader( new InputStreamReader(
								System.in) );
			cin.read();
			
			// shut down
			DHTNode.close(); 
			
		} catch(Exception ex) { ex.printStackTrace(); }
	}
}
